# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: mutantmonkey <aur@mutantmonkey.in>

pkgname=spice-vdagent
pkgver=0.22.1
pkgrel=3
pkgdesc="Spice agent for Linux guests"
arch=('loong64' 'x86_64')
url="https://www.spice-space.org/"
license=('GPL')
depends=('alsa-lib' 'dbus' 'glib2' 'gtk3' 'libdrm' 'libpciaccess' 'libxfixes' 'libxinerama' 'libxrandr' 'systemd')
makedepends=('spice-protocol' 'git')
checkdepends=('procps-ng')
backup=('etc/conf.d/spice-vdagentd')
source=("https://www.spice-space.org/download/releases/$pkgname-$pkgver.tar.bz2")
sha256sums=('93b0d15aca4762cc7d379b179a7101149dbaed62b72112fffb2b3e90b11687a0')

prepare() {
  cd $pkgname-$pkgver
  sed -i 's|/etc/sysconfig/spice-vdagentd|/etc/conf.d/spice-vdagentd|
          s|/usr/sbin/spice-vdagentd|/usr/bin/spice-vdagentd|' data/spice-vdagentd.service
  sed -i 's|/etc/sysconfig/spice-vdagentd|/etc/conf.d/spice-vdagentd|' data/spice-vdagentd.1.in
}

build() {
  cd $pkgname-$pkgver
  ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var --sbindir=/usr/bin \
              --with-session-info=systemd --with-init-script=systemd
  make
}

check() {
  make -C $pkgname-$pkgver check || : # test-session-info fails
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  rm -r "$pkgdir/var"
  install -dm755 "$pkgdir/etc/conf.d/"
  echo 'SPICE_VDAGENTD_EXTRA_ARGS=""' > "$pkgdir/etc/conf.d/spice-vdagentd"
}
